// pages/visitors/visitors.js
import {
  getExhibitionType,
  getExhibitionList
} from "../../api/home"
Page({
  /**
   * 页面的初始数据
   */
  data: {
    top: null,
    active: 1,
    text: "大运河紫檀博物馆大型艺术展览活动",
    time: "2022.10.10-2022.12.12",
    exhibitionTypeList: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    const menu = wx.getMenuButtonBoundingClientRect();
    let system;
    wx.getSystemInfo({
      success(res) {
        system = res
      }
    });
    const top = system.statusBarHeight + menu.height + (menu.top - system.statusBarHeight) * 2;
    // console.log(top)
    this.getExhibitionType();
    this.setData({
      top: top
    })

  },
  onChange(event) {
    wx.showToast({
      title: `切换到标签 ${event.detail.name}`,
      icon: 'none',
    });
  },
  // tab点击事件
  onClick(event) {
    console.log(event.detail.name);
    let id = ''
    switch (event.detail.name) {
      case 'a':
        id = this.data.exhibitionTypeList[0].id
        break;
      case 'b':
        id = this.data.exhibitionTypeList[1].id
          break;
    
      default:
        break;
    }
    this.getExhibitionList(Number(id))
  },
  // 跳转导览详情
  handleToDetail () {
    wx.navigateTo({
      url: '/pages/guide_detail/guideDetail',
    });
      
  },
  // 获取导览类型
  async getExhibitionType () {
    const res = await getExhibitionType();
    this.setData({
      exhibitionTypeList: res.data
    })
    this.getExhibitionList(Number(res.data[0].id));
  },
  // 获取导览列表
  async getExhibitionList (exhibitionId) {
    const res = await getExhibitionList({exhibitionId});
    console.log(res);
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})